package com.junzhiit.nengji.api.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
	
	@Value("${spring.profiles.active}")
	private String profile;
	
	private String localhost = "localhost:8080";
	
	private String dev = "api.dev.legeclub.com:443";
	
	private String sit = "api.sit.legeclub.com:443";
	
	private String prod = "api.legeclub.com:443";
	
	private String DOMIAN = localhost;
	
	private String pathMapping = "/";

	@Bean
    public Docket createRestApi() {
		if(profile.equals("sit")){
			DOMIAN = sit;
			pathMapping = "../";
		}else if(profile.equals("prod")){
			DOMIAN = prod;
			pathMapping = "../";
		}else if(profile.equals("dev")){
			DOMIAN = dev;
			pathMapping = "../";
		}
		
        return new Docket(DocumentationType.SWAGGER_2)
        		.host(DOMIAN).pathMapping(pathMapping)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.junzhiit.nengji.api.web.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("API document for API")
                .description("")
                .contact("BAINA ECO")
                .version("1.0")
                .build();
    }
}
